package de.se.ludoapp.activity.task;

import android.app.Activity;
import android.os.AsyncTask;
import de.se.ludoapp.LudoApplication;

/**
 * Task to destroy game on the server.
 * 
 * @author Marlen Rotert
 * 
 */
public class CloseGameTask extends AsyncTask<String, Integer, String> {

	private LudoApplication ludoApp;
	private Activity context;

	public CloseGameTask(LudoApplication ludoApp, Activity context) {
		super();
		this.ludoApp = ludoApp;
		this.context = context;
	}

	/**
	 * Destroy Game on Server.<br>
	 * This method is executed in a concurrent thread (asynchronous). Therefore
	 * you mustn't accessed on view elements!
	 */
	@Override
	protected String doInBackground(String... params) {
		/* Execute closeGame */
		ludoApp.getLudoStub().closeGame(ludoApp.getCurrentGame());
		return null;
	}

	/**
	 * Back to last Activity and the user has no current game <br>
	 * This method is invoked when the OpenGameTask is executed. You are only
	 * allowed here to access on view Elements (TextView and Buttons)!
	 */
	@Override
	protected void onPostExecute(String result) {
		context.finish();
		ludoApp.setCurrentGame(null);
	}
}
